<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* 题库
*/
class Tiku extends User_Controller {

	public function tlist(){
		$this->load->model("Tk_test_topic_historys");
		$this->load->model("Books");
		$conditions['subject_id'] = 33;
		$subject_data = $this->Books->get_books(0, 100, $conditions);
		
		$this->smarty->assign("menu", 'tiku');
		$this->smarty->assign("subject_list", $subject_data['result']);
		$this->smarty->display("tiku/tlist.html");
	}

	function practice_index($book_id = 0){
		$book_info = get_field_by_where("b_book", "*", "id='{$book_id}'");
		if(!$book_info){
			show_message($_SERVER['HTTP_REFERER'], "课本不存在");exit;
		}
		$this->load->model("Books");
		$conditions['book_id'] = $book_id;
		$subject_list = $this->Books->get_book_chapter_list(0, 100, $conditions);
		$this->smarty->assign("subject_list", $subject_list);
		$this->smarty->assign("book_id", $book_id);
		$this->smarty->assign("book_title", $book_info['title']);
		$this->smarty->display("tiku/practice_index.html");
	}

	function chapter_list($book_id = 0, $limit = 0){
		$book_info = get_field_by_where("b_book", "*", "id='{$book_id}'");
		if(!$book_info){
			show_message($_SERVER['HTTP_REFERER'], "课本不存在");exit;
		}
		$this->load->model("Books");
		$conditions['book_id'] = $book_id;
		$chapter_list = $this->Books->get_book_chapter_list($limit, $this->offset, $conditions);
		$this->smarty->assign("chapter_list", $chapter_list);
		$this->smarty->assign("book_info", $book_info);
		$this->smarty->assign("book_id", $book_id);
		$this->smarty->display("tiku/chapter_list.html");
	}

	//真题冲刺
	//每一个组卷还有两个字段需要查询，1：test_status ｛0、没开始考试，1、正在考试，2、已经交卷｝2：fraction ｛组卷交卷后得到的分数，没做过的是0｝
	function volume_list($type = 1, $subject_id = 0, $home_work_name = 0, $limit = 0){
		$this->left_menu_min['curr'] = '/tiku/test_volume';
		$this->offset = 10;
		if($this->input->post()){
			$limit = 0;
			$post_data = $this->input->post();
			$home_work_name = $post_data['home_work_name'] ? urldecode($post_data['home_work_name']) : 0;
			$subject_id = isset($post_data['subject_id']) ? $post_data['subject_id'] : 0;
			$type = isset($post_data['type']) ? $post_data['type'] : 3;
		}
		if($limit > 0 && is_ajax_request()) $limit = ($limit - 1) * $this->offset ;
		$this->load->model("Topics");
		$conditions = array('subject_id' => $subject_id, 'home_work_name' => $home_work_name, "type" => $type);
		$this->load->model("Test_volumes");
		$result = $this->Test_volumes->get_volume_publish_list($limit, $this->offset, $conditions);

		if(is_ajax_request()){
            if(!empty($result['result'])){
                echo json_encode($result['result']);
            }else{
                echo json_encode(array());
            }
            exit;
        }

		$this->load->library('pagination');
		$page_config['base_url'] = '/user/classes/volume_list/' . $type . '/' . $subject_id . '/' . $home_work_name;
		$page_config['total_rows'] = $result['count'];
		$page_config['per_page'] = $this->offset;
		$page_config['uri_segment'] = 6;

		$this->pagination->initialize($page_config);
		$pagination = $this->pagination->create_links();
		$subject = $this->Topics->get_subject();
		$this->smarty->assign("subject", $subject);
		$this->smarty->assign("test_volume_list", $result['result']);
		$this->smarty->assign("conditions", $conditions);
		$this->smarty->assign("pagination", $pagination);
		$this->smarty->assign("time", time());
		$this->left_menu_min['curr'] = '/classes/volume_list/'.$type;
		$this->smarty->assign("left_menu_min", $this->left_menu_min);
		$this->smarty->assign("type", $type);
		$this->smarty->assign("menu", 'classes');
		$this->smarty->assign("count", ceil($result['count'] / $this->offset)+1);
		$this->smarty->display("tiku/volume_list.html");
	}

	//开始考试（组卷）
	function start_volume_test($id = 0, $ck = 0){

		$id = intval($id);
		$volume_info = get_field_by_where("tk_test_volumes", "*", "id='{$id}'");
		// print_r($volume_info);
		if(!$volume_info){
			show_message("/my/tiku", "组卷不存在");exit;
		}
		if(empty($volume_info['topic_info'])){
			show_message("/my/tiku", "该组卷是空的");exit;
		}

		$volume_history_id = 0;
		$test_topic_historys = array();
		//查询该组卷的考试记录,status = 1的是已经交卷的
		$where = "uid='{$this->user_data['id']}' AND volume_id = '{$id}'";
		$test_volume_history = get_field_by_where("tk_test_volume_historys", "*", " $where ORDER BY id DESC");
		if($test_volume_history && $ck == 0){
			//如果考试记录还没超时就是继续考试
			$time = time();
					
			//如果组卷历史数据没有超时就不做任何操作，如果超时就更新做题时间
			/*if($test_volume_history['timeout_time'] > $time){

			}else{
				//如果已经超时就是重新开始，更新考试时间，开始时间
				$this->db->where("id", $test_volume_history['id']);
				$this->db->update("tk_test_volume_historys", array("status"=>0, "begin_time" => $time, "timeout_time" => $volume_info[$type.'_timeout']*60+$time));
			}*/
			if($ck == 1){
				$this->db->where("id", $test_volume_history['id']);
				$this->db->update("tk_test_volume_historys", array("status"=>0, "begin_time" => $time));
			}
			$volume_history_id = $test_volume_history['id'];
			//如果不是新开始的组卷做题，就先查询做题记录，用于配合前端显示题目是否已经做过的状态
			$this->load->model("Tk_test_topic_historys");
			$conditions['uid'] = $this->user_data['id'];
			$conditions['volume_history_id'] = $volume_history_id;
			$test_topic_historys = $this->Tk_test_topic_historys->get_answer_topic($conditions);
			if($test_topic_historys){
				$test_topic_historys['ids'] = array_map('array_shift', $test_topic_historys);
			}
		}else{
			//没有记录就写入组卷答题记录
			$test_volume_history_data['uid'] = $this->user_data['id'];
			$test_volume_history_data['volume_id'] = $volume_info['id'];
			$test_volume_history_data['percentage'] = 0;
			$test_volume_history_data['status'] = 0;
			$test_volume_history_data['begin_time'] = time();
			$this->db->insert("tk_test_volume_historys", $test_volume_history_data);
			$volume_history_id = $this->db->insert_id();
			if($ck == 1){
				// redirect("/tiku/start_volume_test/" . $id);
			}
		}


		$this->load->model("Topics");
		$topic_list = $this->Topics->get_topic_list(0, 0, array("id" => $volume_info['topic_info'], "order" => "type ASC"));
		// print_r($test_topic_historys);exit;
		if(isset($topic_list['count']) && $topic_list['count'] > 0){
			$volume_info['topic_list'] = array();
			$volume_info['no_topic_total'] = $volume_info['topic_total'] = $topic_list['count'];
			$first_topic = current($topic_list['result']);
			$volume_info['first_topic'] = $first_topic['id'];
			$need_first = true;
			$volume_info['has_answer_num'] = $volume_info['no_has_answer_num'] = 0;
			$fh = array(1 => "+", 2 => "-", 3 => "×", 4 => "÷", 5 => "(", 6 => ")");
			foreach ($topic_list['result'] as $key => $value) {
				$value['has_answer'] = 0;
				if(isset($test_topic_historys['ids']) && in_array($value['id'], $test_topic_historys['ids'])){
					$value['has_answer'] = 1;
					$volume_info['no_topic_total']--;
					foreach ($test_topic_historys as $k => $v) {
						if(!empty($v['topic_id']) && $v['topic_id'] == $value['id']){
							$value['answer_list'] = explode(",", $v['user_answers']);
						}
					}
					$volume_info['has_answer_num'] += 1;
				}else{
					//获取第一个未做题的ID
					$volume_info['no_has_answer_num'] += 1;
					if($need_first == true) {
						$volume_info['first_topic'] = $value['id'];
						$need_first = false;
					}
				}

				//查询答案,简答题不用查询答案
				if($value['type'] == 1 ||$value['type'] == 2 || $value['type'] == 3){
					$topic_result = $this->Topics->get_topic_reuslt($value['id']);
					if($topic_result){
						$value['result'] = $topic_result;
					}
				}elseif($value['type'] == 6){
					$calc = $this->Topics->get_topic_calc($value['id']);
					if($calc){
						$value['calc'] = '';
						foreach ($calc as $k => $f) {
							# code...
							if($f['type'] == 1){
								$value['calc'] .= $f['value'] . " ";
							}else{
								$value['calc'] .= $fh[$f['value']] . " ";
							}
						}
					}
				}
				$volume_info['topic_list'][$value['type']][] = $value;
			}
		}else{
			show_message("/my/tiku", "组卷中的题目不可用");exit;
		}
		// print_r($volume_info);
		$letter = array('A','B','C','D');
		$this->smarty->assign("letter", $letter);
		$this->smarty->assign("volume_history_id", $volume_history_id);
		$this->smarty->assign("volume_info", $volume_info);
		$this->smarty->assign("start_type", 'volume');
		$this->smarty->display("tiku/start_volume_test.html");
	}

	function save_topic_answer(){
		$post_data = $this->input->post();
		if(is_ajax_request()){
			if(empty($post_data['topic_id'])){
				show_message($_SERVER['HTTP_REFERER'], "未选择答题题目");exit;
			}
			if(empty($post_data['answer_id']) && !isset($post_data['user_answers']) ){
				show_message($_SERVER['HTTP_REFERER'], "请选择一个答案");exit;
			}
			/*if(empty($post_data['volume_id']) || empty($post_data['volume_history_id'])){
				echo '缺少考卷'; exit;//缺少题目ID
			}*/
			//获取题目数据
			$topic_id = intval($post_data['topic_id']);
			$topic_info = get_field_by_where("tk_topics", "id,type,subject_id,chapter_id,subject_text,analysis", "id=$topic_id");
			if(!$topic_info){
				show_message($_SERVER['HTTP_REFERER'], "题目不存在");exit;
			}
			
			if(!empty($post_data['volume_id'])){
				$volume_id = intval($post_data['volume_id']);
				//获取考卷数据
				$test_volume_info = get_field_by_where("tk_test_volumes", "id,subject_id,chapter_id,template_id", "id='{$volume_id}'");
				if(!$test_volume_info){
					show_message($_SERVER['HTTP_REFERER'], "考卷不存在");exit;
				}

				//获取组卷的模版信息
				$test_volume_template_info = get_field_by_where("tk_test_volume_templates", "*", "id='{$test_volume_info['template_id']}'");
				if(!$test_volume_template_info){
					show_message($_SERVER['HTTP_REFERER'], "考卷模版不存在");exit;
				}
			}
			
			//获取考题正确答案
			$this->load->model("Topics");
			$is_right = 1;
			$topic_result = $this->Topics->get_topic_reuslt($topic_id);
			$right_topic = array();
			if($topic_info['type'] == 8 || $topic_info['type'] == 9){
				$is_right = 0;
			}elseif($topic_info['type'] == 5){
				if(!$topic_result){
					show_message($_SERVER['HTTP_REFERER'], "异常的题目,缺少答案");exit;
				}

				foreach ($topic_result as $key => $value) {
					if(!isset($post_data['user_answers'][$key]) || $value['answer_text'] != $post_data['user_answers'][$key]){
						$is_right = 0;
					}
				}
			}elseif($topic_info['type'] == 6){
				//计算题只有一个答案
				$topic_result = get_field_by_where("tk_topic_result", "*", "topic_id='{$topic_id}'");
				if(!$topic_result){
					show_message($_SERVER['HTTP_REFERER'], "异常的题目,缺少答案");exit;
				}
				if($topic_result['answer_text'] == trim($post_data['user_answers'])){
					$is_right = 1;
				}else{
					$is_right = 0;
				}
				$right_topic = $topic_result['answer_text'];
			}elseif($topic_info['type'] == 7){
				//列算式的题目可能有多个正确的算式
				$topic_result = $this->Topics->get_topic_reuslt($topic_id);
				if(!$topic_result){
					//题目未标记任何一个正确答案
					show_message($_SERVER['HTTP_REFERER'], "异常的题目");exit;
				}
				$is_right = 0;	//是否做对

				//替换乘除号
				$user_answers = str_replace("×", "*", $post_data['user_answers']);
				$user_answers = str_replace("÷", "/", $user_answers);
				
				$need_calc = true;	//是否需要计算系统存的结果，如果系统中的答案不存在等于号就需要计算
				$calc_str = '';	//生成计算公式，配合$need_calc使用
				$topic_result_array = array();
				foreach ($topic_result as $key => $value) {
					$topic_result_array[] = $value['answer_text'];
					$calc_str .= $value['answer_text'];
					if($value['answer_text'] == '='){
						$need_calc = false;
					}
				}
				if($need_calc == true){
					$calc_str = preg_replace('#[^+\-*/\(\).0-9]#', '', $calc_str);
					$topic_result_array[] = "=";
					$topic_result_array[] = eval("return {$calc_str};");
				}

				$user_answers_array = array();

				if(strpos($user_answers,"=") === false){
					$user_answers = preg_replace('#[^+\-*/\(\).0-9]#', '', $user_answers);
					//提交的答案中没有等于号
					$user_answers_array[] = "=";
					$user_answers_array[] = eval("return {$user_answers};");
				}else{
					//提交的答案中有等于号
					$user_answer_arr = explode("=", $user_answers);
					$user_answers = $user_answer_arr[0];
					$user_answers_array[] = "=";
					$user_answers_array[] = $user_answer_arr[1];
				}
				$str_array = create_str_array($user_answers);
				$user_answers_array = array_merge($topic_result_array, $str_array);
				$diff = array_diff($topic_result_array,$user_answers_array);
				if(!$diff){
					$is_right = 1;
				}
			}else{
				$topic_result = $this->Topics->get_topic_reuslt($topic_id);
				$right_topic = array();
				if(!$topic_result){
					//题目未标记任何一个正确答案
					show_message($_SERVER['HTTP_REFERER'], "异常的题目");exit;
				}else{
					//判断是否做对
					foreach ($topic_result as $key => $value) {
						if($value['is_right'] == 1){
							$right_topic[] = $value['id'];
						}
						if($value['is_right'] == 1 && !in_array($value['id'], $post_data['answer_id'])){
							$is_right = 0;
						}elseif($value['is_right'] == 0 && in_array($value['id'], $post_data['answer_id'])){
							$is_right = 0;
						}
					}
				}
			}
			
			//查询题目是否已经做过
			$where = "uid={$this->user_data['id']} AND topic_id = $topic_id ";
			if(!empty($post_data['volume_id'])){
				$where .= " AND volume_id = $volume_id ";
			}
			if(!empty($post_data['volume_history_id'])){
				$where .= " AND volume_history_id = {$post_data['volume_history_id']} ";
			}
			if(!empty($post_data['type'])){
				$where .= " AND type = '{$post_data['type']}' ";
			}
			if(!empty($post_data['data_id'])){
				$where .= " AND data_id = '{$post_data['data_id']}' ";
			}
			$test_topic_history_info = get_field_by_where("tk_test_topic_historys", "id", $where);

			//格式化模版content
			$fraction = 0;
			if(!empty($post_data['volume_id'])){
				$template_content = json_decode($test_volume_template_info['content'], true);

				//公共数据（修改和添加都要的）
				$fraction = 0;
			}
			$test_topic_history['fraction'] 			= $fraction;
			$test_topic_history['is_right'] 			= $is_right;
			if(isset($post_data['bdx'])){
				$test_topic_history['user_answers'] 	= json_encode($post_data['bdx']);
			}elseif(isset($post_data['analys'])){
				$test_topic_history['user_answers'] 	= json_encode($post_data['analys']);
			}else{
				if($topic_info['type'] == 5){
					$user_answers = json_encode($post_data['user_answers']);
				}elseif($topic_info['type'] == 6 || $topic_info['type'] == 7) {
					$user_answers = $post_data['user_answers'];
				}else{
					$user_answers = implode(",", $post_data['answer_id']);
				}
				$test_topic_history['user_answers'] 	= $user_answers;
			}
			$test_topic_history['add_time'] 			= time();
			if(!$test_topic_history_info){
				//写入做题记录
				$test_topic_history['uid'] 				= $this->user_data['id'];
				$test_topic_history['subject_id'] 		= $topic_info['subject_id'];
				$test_topic_history['chapter_id'] 		= $topic_info['chapter_id'];
				$test_topic_history['topic_id'] 		= $topic_id;
				$test_topic_history['volume_id'] 		= !empty($post_data['volume_id']) ? $volume_id : 0;;
				$test_topic_history['volume_history_id']= !empty($post_data['volume_history_id']) ? $post_data['volume_history_id'] : 0;
				/*$test_topic_history['type'] 			= !empty($post_data['type']) ? $post_data['type'] : 0;
				$test_topic_history['data_id']			= !empty($post_data['data_id']) ? $post_data['data_id'] : 0;*/
				$test_topic_history['topic_type'] 		= $topic_info['type'];
				$test_topic_history['subject_text'] 	= $topic_info['subject_text'];
				$test_topic_history['analysis'] 		= $topic_info['analysis'];
				$this->db->insert("tk_test_topic_historys", $test_topic_history);
			}else{
				//修改做题记录
				$this->db->where("id", $test_topic_history_info['id']);
				$this->db->update("tk_test_topic_historys", $test_topic_history);
			}

			//考卷做题，修改考卷的考试报告字段
			if(!empty($post_data['volume_history_id'])){
				$this->load->model("Tk_test_topic_historys");
				$conditions['uid'] = $this->user_data['id'];
				$conditions['volume_history_id'] = $post_data['volume_history_id'];
				$test_topic_historys = $this->Tk_test_topic_historys->get_answer_topic($conditions);
				$right_percentage = 0;
				$data['percentage'] = ceil(count($test_topic_historys) / $test_volume_template_info['total_topic'] * 100); //答题率
				$data['fraction'] = 0;
				$data['status'] = 0;
				foreach ($test_topic_historys as $key => $value) {
					if($value['is_right']){
						$right_percentage += 1;
						$data['fraction'] += $value['fraction'];;
					}
				}
				// $data['right_percentage'] = ceil($right_percentage / $test_volume_template_info['total_topic'] * 100);
				if(count($test_topic_historys) > 0) $data['right_percentage'] = ceil($right_percentage / count($test_topic_historys) * 100);

				$this->db->where("id", $post_data['volume_history_id']);
				$this->db->update("tk_test_volume_historys", $data);
			}
			// print_r($topic_result);
			echo json_encode(array("code" => 1, "is_right" => $is_right, "right_topic" => $right_topic));
		}else{
			show_message($_SERVER['HTTP_REFERER'], "非法操作");exit;
		}		
	}

	//交卷
	function save_volume(){
		$post_data = $this->input->post();
		// print_r($post_data);exit;
		if(empty($post_data['test_volume_history_id'])){
			show_message($_SERVER['HTTP_REFERER'], "非法操作");exit;
		}else{
			$test_volume_history = get_field_by_where("tk_test_volume_historys", "volume_id", "id = '{$post_data['test_volume_history_id']}'");
			if(!$test_volume_history){
				show_message($_SERVER['HTTP_REFERER'], "考卷历史数据不存在");exit;
			}
			

			$test_volume_info = get_field_by_where("tk_test_volumes", "id,subject_id,chapter_id,template_id", "id='{$test_volume_history['volume_id']}'");
			if(!$test_volume_info){
				show_message($_SERVER['HTTP_REFERER'], "考卷不存在");exit;
			}

			

			//获取组卷的模版信息
			$test_volume_template_info = get_field_by_where("tk_test_volume_templates", "*", "id={$test_volume_info['template_id']}");
			if(!$test_volume_template_info){
				show_message($_SERVER['HTTP_REFERER'], "考卷模版不存在");exit;
			}
			// print_r($test_volume_template_info);
			$this->load->model("Tk_test_topic_historys");
			$conditions['uid'] = $this->user_data['id'];
			$conditions['volume_history_id'] = $post_data['test_volume_history_id'];
			$test_topic_historys = $this->Tk_test_topic_historys->get_answer_topic($conditions);
			$template_content = json_decode($test_volume_template_info['content'], true);
			$right_percentage = 0;
			$data['percentage'] = ceil(count($test_topic_historys) / $test_volume_template_info['total_topic'] * 100); //答题率
			$data['fraction'] = 0;
			$data['status'] = 1;
			
			/*$topic_type = array(
								1 => array("total"=>$template_content[1]['number'],"mytotal"=>0),
								2 => array("total"=>$template_content[2]['number'],"mytotal"=>0),
								3 => array("total"=>$template_content[3]['number'],"mytotal"=>0),
								4 => array("total"=>$template_content[4]['number'],"mytotal"=>0),
								7 => array("total"=>$template_content[7]['number'],"mytotal"=>0),
								8 => array("total"=>$template_content[8]['number'],"mytotal"=>0),
								9 => array("total"=>$template_content[9]['number'],"mytotal"=>0)
							);*/
			foreach ($template_content as $key => $value) {
				$topic_type[$key] = array("total" => $value['number'],"mytotal" => 0);
			}
			foreach ($test_topic_historys as $key => $value) {
				if($value['is_right']){
					$right_percentage += 1;
					$data['fraction'] += $value['fraction'];;
				}
				if(isset($topic_type[$value['topic_type']]['mytotal'])){
					$topic_type[$value['topic_type']]['mytotal'] += 1; 
				}
			}
			// $data['right_percentage'] = ceil($right_percentage / $test_volume_template_info['total_topic'] * 100);
			if(count($test_topic_historys) > 0) $data['right_percentage'] = ceil($right_percentage / count($test_topic_historys) * 100);
			$data['end_time'] = time();
			$data['report'] = json_encode(array("total_topic"=>$test_volume_template_info['total_topic'],"total_fraction"=>$test_volume_template_info['total_fraction'],"total_topic"=>$test_volume_template_info['total_topic'],"topic_type"=>$topic_type));
			$this->db->where("id", $post_data['test_volume_history_id']);
			$this->db->update("tk_test_volume_historys", $data);
			show_message('/my/classes/volume_list', "交卷成功");exit;
		}
	}

	//开始考试（组卷）
	function start_topic_test($chapter_id = 0, $show_topic_id = 0){

		$chapter_id = intval($chapter_id);
		$chapter_info = get_field_by_where("b_book_chapter", "*", "id=$chapter_id");
		$this->load->model("Topics");
		$conditions['chapter_id'] = $chapter_id;
		$conditions['order'] = "type ASC";

		$conditions['uid'] = $this->user_data['id'];
		$topic_list = $this->Topics->get_topic_list(0, 0, $conditions);
		$volume_info = $chapter_info;
		$volume_info['name'] = $chapter_info['title'];
		if(isset($topic_list['count']) && $topic_list['count'] > 0){
			$volume_info['topic_list'] = array();
			$volume_info['no_topic_total'] = $volume_info['topic_total'] = $topic_list['count'];
			$first_topic = current($topic_list['result']);
			$volume_info['first_topic'] = $first_topic['id'];
			$need_first = true;
			$volume_info['has_answer_num'] = $volume_info['no_has_answer_num'] = 0;
			$fh = array(1 => "+", 2 => "-", 3 => "×", 4 => "÷", 5 => "(", 6 => ")");
			foreach ($topic_list['result'] as $key => $value) {
				$value['has_answer'] = 0;
				if(isset($test_topic_historys['ids']) && in_array($value['id'], $test_topic_historys['ids'])){
					$value['has_answer'] = 1;
					$volume_info['no_topic_total']--;
					foreach ($test_topic_historys as $k => $v) {
						if(!empty($v['topic_id']) && $v['topic_id'] == $value['id']){
							$value['answer_list'] = explode(",", $v['user_answers']);
						}
					}
					$volume_info['has_answer_num'] += 1;
				}else{
					//获取第一个未做题的ID
					$volume_info['no_has_answer_num'] += 1;
					if($need_first == true) {
						$volume_info['first_topic'] = $value['id'];
						$need_first = false;
					}
				}
				if($show_topic_id > 0) $volume_info['first_topic'] = $show_topic_id;

				//查询答案,简答题不用查询答案
				if($value['type'] == 1 ||$value['type'] == 2 || $value['type'] == 3){
					$topic_result = $this->Topics->get_topic_reuslt($value['id']);
					if($topic_result){
						$value['result'] = $topic_result;
					}
				}elseif($value['type'] == 6){
					$calc = $this->Topics->get_topic_calc($value['id']);
					if($calc){
						$value['calc'] = '';
						foreach ($calc as $k => $f) {
							# code...
							if($f['type'] == 1){
								$value['calc'] .= $f['value'] . " ";
							}else{
								$value['calc'] .= $fh[$f['value']] . " ";
							}
						}
					}
				}
				$volume_info['topic_list'][$value['type']][] = $value;
			}
		}else{
			show_message("/my/tiku", "组卷中的题目不可用");exit;
		}
		// print_r($chapter_info);
		$letter = Array( // 半角
			        'A', 'B', 'C', 'D', 'E',
			        'F', 'G', 'H', 'I', 'J',
			        'K', 'L', 'M', 'N', 'O',
			        'P', 'Q', 'R', 'S', 'T',
			        'U', 'V', 'W', 'X', 'Y',
			        'Z'
			    );

		$this->smarty->assign("letter", $letter);
		$this->smarty->assign("volume_info", $volume_info);
		$this->smarty->display("tiku/start_volume_test.html");
	}
}
